from odoo import api, fields, models


class StockPickingType(models.Model):
    _inherit = 'stock.picking.type'

    code = fields.Selection(selection_add=[
        ('purchase_qt', 'Purchase TI')
    ], ondelete={'purchase_qt': lambda recs: recs.write({'code': 'incoming', 'active': False})})
    count_qt_todo = fields.Integer(string="待处理", compute='_get_qt_count')
    count_qt_out = fields.Integer(string="Subcon Out", compute='_get_qt_count')
    count_qt_in = fields.Integer(string="Subcon In", compute='_get_qt_count')

    def _get_qt_count(self):
        for record in self:
            record.count_qt_todo = len(self.env['stock.subcon.outside'].sudo().search([('subcon_in', '=', False)]))
            record.count_qt_out = len(self.env['stock.subcon.outside'].sudo().search([('subcon_out', '=', False)]))
            record.count_qt_in = len(self.env['stock.subcon.outside'].sudo().search([('subcon_in', '=', False)]))
